Finished up initial revision of GtkCellAreaBoxIter
authorTristan Van Berkom <tristan.van.berkom@gmail.com>
Tue, 26 Oct 2010 14:01:17 +0000 (23:01 +0900)
committerTristan Van Berkom <tristan.van.berkom@gmail.com>
Tue, 26 Oct 2010 14:01:17 +0000 (23:01 +0900)
The interaction between this class and GtkCellAreaBox could
use some optimization, maybe the cells and their sizes should
be returned as a list and iterated over at the same time as
requesting sizes instead of the hash table approach currently
taken, however the code is clean this way for now.

gtk/gtkcellareaboxiter.c
gtk/gtkcellareaboxiter.h

index f0c79746a0d967fafe68052382758225eb2f932d..568f84dffca13290209fb9fda94d345a4edf9951 100644 (file)
@@ -337,9 +337,31 @@ gtk_cell_area_box_get_cell_width (GtkCellAreaBoxIter *box_iter,
                                  gint               *minimum_width,
                                  gint               *natural_width)
 {
+  GtkCellAreaBoxIterPrivate *priv;
+  CachedSize                *size;
+
   g_return_if_fail (GTK_IS_CELL_AREA_BOX_ITER (box_iter));
   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
 
+  priv = box_iter->priv;
+  size = g_hash_table_lookup (priv->base_widths, renderer);
+
+  if (size)
+    {
+      if (minimum_width)
+       *minimum_width = size->min_size;
+
+      if (natural_width)
+       *natural_width = size->nat_size;
+    }
+  else
+    {
+      if (minimum_width)
+       *minimum_width = -1;
+
+      if (natural_width)
+       *natural_width = -1;      
+    }
 }
 
 void
@@ -349,20 +371,68 @@ gtk_cell_area_box_get_cell_height_for_width (GtkCellAreaBoxIter *box_iter,
                                             gint               *minimum_height,
                                             gint               *natural_height)
 {
+  GtkCellAreaBoxIterPrivate *priv;
+  GHashTable                *cell_table;
+  CachedSize                *size = NULL;
+
   g_return_if_fail (GTK_IS_CELL_AREA_BOX_ITER (box_iter));
   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
 
+  priv       = box_iter->priv;
+  cell_table = g_hash_table_lookup (priv->heights, GINT_TO_POINTER (for_width));
+
+  if (cell_table)
+    size = g_hash_table_lookup (cell_table, renderer);
+
+  if (size)
+    {
+      if (minimum_height)
+       *minimum_height = size->min_size;
+
+      if (natural_height)
+       *natural_height = size->nat_size;
+    }
+  else
+    {
+      if (minimum_height)
+       *minimum_height = -1;
+
+      if (natural_height)
+       *natural_height = -1;      
+    }
 }
 
 void
 gtk_cell_area_box_get_cell_height (GtkCellAreaBoxIter *box_iter,
                                   GtkCellRenderer    *renderer,
-                                  gint                minimum_height,
-                                  gint                natural_height)
+                                  gint               *minimum_height,
+                                  gint               *natural_height)
 {
+  GtkCellAreaBoxIterPrivate *priv;
+  CachedSize                *size;
+
   g_return_if_fail (GTK_IS_CELL_AREA_BOX_ITER (box_iter));
   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
 
+  priv = box_iter->priv;
+  size = g_hash_table_lookup (priv->base_heights, renderer);
+
+  if (size)
+    {
+      if (minimum_height)
+       *minimum_height = size->min_size;
+
+      if (natural_height)
+       *natural_height = size->nat_size;
+    }
+  else
+    {
+      if (minimum_height)
+       *minimum_height = -1;
+
+      if (natural_height)
+       *natural_height = -1;      
+    }
 }
 
 void
@@ -372,7 +442,33 @@ gtk_cell_area_box_get_cell_width_for_height (GtkCellAreaBoxIter *box_iter,
                                             gint               *minimum_width,
                                             gint               *natural_width)
 {
+  GtkCellAreaBoxIterPrivate *priv;
+  GHashTable                *cell_table;
+  CachedSize                *size = NULL;
+
   g_return_if_fail (GTK_IS_CELL_AREA_BOX_ITER (box_iter));
   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
 
+  priv       = box_iter->priv;
+  cell_table = g_hash_table_lookup (priv->widths, GINT_TO_POINTER (for_height));
+
+  if (cell_table)
+    size = g_hash_table_lookup (cell_table, renderer);
+
+  if (size)
+    {
+      if (minimum_width)
+       *minimum_width = size->min_size;
+
+      if (natural_width)
+       *natural_width = size->nat_size;
+    }
+  else
+    {
+      if (minimum_width)
+       *minimum_width = -1;
+
+      if (natural_width)
+       *natural_width = -1;      
+    }
 }
index 36f25bea5ac2b40ed810976d96584e4df0958a17..2d962f4f60eb3c0233e483b325af80eaf42f9dc3 100644 (file)
@@ -97,8 +97,8 @@ void    gtk_cell_area_box_get_cell_height_for_width   (GtkCellAreaBoxIter *box_i
 
 void    gtk_cell_area_box_get_cell_height             (GtkCellAreaBoxIter *box_iter,
                                                       GtkCellRenderer    *renderer,
-                                                      gint                minimum_height,
-                                                      gint                natural_height);
+                                                      gint               *minimum_height,
+                                                      gint               *natural_height);
 
 void    gtk_cell_area_box_get_cell_width_for_height   (GtkCellAreaBoxIter *box_iter,
                                                       GtkCellRenderer    *renderer,